package com.fancon.rage.comic.vn.gui;

import java.util.ArrayList;

import com.fancon.rage.comic.vn.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Paginator extends LinearLayout {
	private Context mContext;
	private ArrayList<ImageView> mPages = new ArrayList<ImageView>();

	public Paginator(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		// TODO Auto-generated constructor stub
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.paginator, this);
	}

	public void removeAllChild() {
		LinearLayout container = (LinearLayout) findViewById(R.id.container);
		mPages = new ArrayList<ImageView>();
		container.removeAllViews();
	}

	public void addPage() {
		LinearLayout container = (LinearLayout) findViewById(R.id.container);
		ImageView circle = new ImageView(mContext);
		circle.setImageResource(R.drawable.page_indicator);
		mPages.add(circle);
		container.addView(circle);
	}

	public ArrayList<ImageView> getmPages() {
		return mPages;
	}

	public void setmPages(ArrayList<ImageView> mPages) {
		this.mPages = mPages;
	}

	public void selectedPage(Integer position) {
		for (ImageView img : mPages) {
			img.setImageResource(R.drawable.page_indicator);
		}
		ImageView circle = mPages.get(position);
		circle.setImageResource(R.drawable.page_indicator_active);
	}

}
